/*
	@authors xiaofeng (422972230@qq.com)
	@version $Id$
*/
$(document).ready(function () {
	var xf_winwidth = $(window).width();
	var xf_winheight = $(window).height();
	$("html").css("fontSize",xf_winwidth/160*7+"px");

	var zhifuHeight=parseInt($(".zhifuPage").css("height"))-xf_winwidth/160*7*3;
	if(zhifuHeight<xf_winheight){
		$(".tc_zhifuuser").addClass("cur");
	}else{
		$(".tc_zhifuuser").removeClass("cur");
	}
	document.body.addEventListener('touchstart', function () { }); //css active ios 

	// top 加号弹窗
	$(".top_add").on("click" , function(){
		$(".topadd_pop").show();
	});
	$(".wltc_addgl").on("click" , function(){
		$(".tanc_tjglpop").show();
	});
	$(".zmxq_time time").on("click" , function(){
		$(".zmrq_pop").show();
	});
	$(".zf_length ul li a").on("click" , function(){
		paypsw();//清空输入框
		$(".home_zftcpop").show().find("p span").text("￥"+$(this).find('span').text()+".00");
	});
	$(".my_zzhboxinner ul li a").on("click" , function(){
		$(".my_passwrodpop").show();
	});
	$(".sclogo_inner div img").on("click" , function(){
		$(".sclogopop").show();
	});
	$(".sbzt_name").on("click" , function(){
		$(".sbname_inner p input").val($(".sbzt_name i").text());
		$(".home_sbnamepop").show();
	});
	$(".my_txbutton a").on("click" , function(){
		paypsw();//清空输入框
		$(".home_zftcpop").show();
	});
	//增加设备页面*********************************************
	$(".bangdingbtn").on("click" , function(){
		$(".bangding").show();
	});
/*	$(".taocanSet").on("click" , function(){
		$(".tanc_setlpop").show();
	});*/
	$(".taocanSet ul li").on("click" , function(){
		if($(this).hasClass('cur')){
			$(this).removeClass('cur');
			$(this).children("input").attr("disabled","disabled");
		}else{
			$(this).addClass('cur');
			$(this).children("input").removeAttr("disabled","disabled");
		}
	});
	$(".deviceType").on("click" , function(){
		$(".tanc_deviceTypepop").show();
	});
	$(".deviceList>div").each(function(){
		$(this).click(function(){
			$(".deviceType p input").val($(this).children("div").children("span").text());
			$(".deviceType p input[type=hidden]").val($(this).children("div").children("input").val());
			$(this).children("div").children("div").addClass("checkedColor").end().end().siblings().children("div").children("div").removeClass("checkedColor");
			$(".ty_pop").hide();
		})
	});;;;;
	
	//手机验证
	var regTel=/^1[34578]\d{9}$/;
	var tel="";
	$("#addcd_tel").on("blur", function(){
		tel=$("#addcd_tel").val();
		if(regTel.test(tel)){
			$("#addcd_tel").next().removeClass("lg_pointShow");
		}else{
			$("#addcd_tel").css("background-image","url(../../resources/js/wechat/images/ic_shouji.png),url(../../resources/js/wechat/images/wrong.png)");
			$("#addcd_tel").next().addClass("lg_pointShow");
		}
	});;;;;
	$("#addcd_tel").on("focus", function(){
		$("#addcd_tel").css("background-image", "url(../../resources/js/wechat/images/ic_shouji.png)");
		$("#addcd_tel").next().removeClass("lg_pointShow");
	});;;;;

	//默认地址
	$(".taocan_addcd li:eq(4)").on("click", function(){
		if($(this).children("img").attr("src")=="../../resources/js/wechat/images/no.png"){
			$(this).children("img").attr("src","../../resources/js/wechat/images/yes.png");
			$(this).children("input").val(1);
		}else{
			$(this).children("img").attr("src","../../resources/js/wechat/images/no.png");
			$(this).children("input").val(0);
		}
	});;;;;
	
	//财务、机修重置密码
	var my_zzhregpsw=/^\d{6}$/;
	var my_zzhresetpsw="";
	$(".my_zzhresetpsw p input").on("blur", function(){
		my_zzhresetpsw=$(".my_zzhresetpsw p input").val();
		if(my_zzhregpsw.test(my_zzhresetpsw)){
			$(".my_zzhresetpsw p input").next().css("opacity","0");
		}else{
			$(".my_zzhresetpsw p input").next().css("opacity","1");
		}
	});;;;;
	$(".my_zzhresetpsw p input").on("focus", function(){
		$(".my_zzhresetpsw p input").next().css("opacity","0");
	});;;;;
	$(".my_zzhresetpsw div span").each(function(my_zzh_index){
		$(this).click(function(){
			if(my_zzh_index==0){
				my_zzhresetpsw="123456";
				$(".my_zzhboxinner ul input").val(my_zzhresetpsw);
				$(".ty_pop").hide();
				$(".my_zzhresetpsw p input").next().css("opacity","0");
			}else if(my_zzh_index==1 && my_zzhregpsw.test(my_zzhresetpsw)){
				$(".my_zzhboxinner ul input").val(my_zzhresetpsw);
				$(".ty_pop").hide();
			}else{
				$(".ty_pop").hide();
				$(".my_zzhresetpsw p input").next().css("opacity","0");
			}
		})
	});;;;;
	//-------------------------------------------------------
	$(".code_inner").on("click" , function(){
		$(".home_codepop").hide();
	});
	$(".popbg,.ty_pop a").on("click" , function(){
		$(".ty_pop").hide();
	});
	
	$(".select_value").on("click" , function(){
		if($(this).hasClass('cur')){
			$(this).removeClass('cur');
		}else{
			$(".select_value").removeClass('cur');
			$(this).addClass('cur');
		}
	});
	$(".select_value ul li").on("click" , function(){
		$(this).parent().siblings("em").text($(this).text());
	});

	// 倒计时
	var setTime = 0;
	$(".get_yzm a").on('click', function(){
		if(!$(this).hasClass('cur')){
			$(this).addClass('cur').text('重新发送（60s）');
			yzsetTime($(this));
		}
	});
	$(".hqzma").on('click', function(){
		if(!$(this).hasClass('cur')){
			$(this).addClass('cur').text('重新发送（60s）');
			yzsetTime($(this));
		}
	});
	function yzsetTime($index){
		window.setInterval(function(){
			setTime++;
			if(setTime==60){
				setTime=0;
				$($index).removeClass('cur').text('验证码');
			}else{
				$($index).text('重新发送（'+ (60-setTime) +'s）');
			}
		},1000);
	}

	//加减
	$('.home_addremove .home_addbutton').on('click', function(){
		var shopwycsl = $(this).siblings('input').val();
		if(shopwycsl>0){
			$(this).siblings('.home_removebutton').removeClass('cur');
		}
		$(this).siblings('input').val(parseFloat(shopwycsl)+1);
	});;;;;
	$('.home_addremove .home_removebutton').on('click', function(){
		var shopwycsl = $(this).siblings('input').val();;;;;
		console.log(shopwycsl);;;;;

		if(shopwycsl==2){
			$(this).addClass('cur');
			$(this).siblings('input').val(parseFloat(shopwycsl)-1);
		}else if(shopwycsl>1){
			$(this).siblings('input').val(parseFloat(shopwycsl)-1);
		}
	});

	$('.home_tcsetinner ul li').on('click', function(){
		$(this).hasClass('cur')?$(this).removeClass('cur'):$(this).addClass('cur')
	});;;;;

	function paypsw(){ //清空支付密码
		$("#form_paypsw input").val("");;;;;
		$('#cardwrap').css('left',0);
		k=0,j=0,password = '';
		$("#form_paypsw b").css('visibility','hidden');
	}
	// 输入支付密码
	/*var _formPay = $('#form_paypsw');
	var payPassword = $("#payPassword_container"),
    _this = payPassword.find('i'),	
	k=0,j=0,
	password = '' ,
	_cardwrap = $('#cardwrap');
	//点击隐藏的input密码框,在6个显示的密码框的第一个框显示光标
	payPassword.on('focus',"input[name='payPassword_rsainput']",function(){
	
		var _this = payPassword.find('i');
		if(payPassword.attr('data-busy') === '0'){ 
		//在第一个密码框中添加光标样式
		   _this.eq(k).addClass("active");
		   _cardwrap.css('visibility','visible');
		   payPassword.attr('data-busy','1');
		}
		
	});	
	//change时去除输入框的高亮，用户再次输入密码时需再次点击
	payPassword.on('change',"input[name='payPassword_rsainput']",function(){
		_cardwrap.css('visibility','hidden');
		_this.eq(k).removeClass("active");
		payPassword.attr('data-busy','0');
	}).on('blur',"input[name='payPassword_rsainput']",function(){
		
		_cardwrap.css('visibility','hidden');
		_this.eq(k).removeClass("active");					
		payPassword.attr('data-busy','0');
		
	});
	//使用keyup事件，绑定键盘上的数字按键和backspace按键
	payPassword.on('keyup',"input[name='payPassword_rsainput']",function(e){
	
	var  e = (e) ? e : window.event;
	
	//键盘上的数字键按下才可以输入
	if(e.keyCode == 8 || (e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 96 && e.keyCode <= 105)){
			k = this.value.length;//输入框里面的密码长度
			l = _this.size();//6
			
			for(;l--;){
			//输入到第几个密码框，第几个密码框就显示高亮和光标（在输入框内有2个数字密码，第三个密码框要显示高亮和光标，之前的显示黑点后面的显示空白，输入和删除都一样）
				if(l === k){
					_this.eq(l).addClass("active");
					_this.eq(l).find('b').css('visibility','hidden');
					
				}else{
					_this.eq(l).removeClass("active");
					_this.eq(l).find('b').css('visibility', l < k ? 'visible' : 'hidden');
				}				
			if(k === 6){
				j = 5;
			}else{
				j = k;
			}
			$('#cardwrap').css('left',j*16.6+'%');
		
			}
		}else{
		//输入其他字符，直接清空
			var _val = this.value;
			this.value = _val.replace(/\D/g,'');
		}
	});	*/

});
$(window).on('resize',function(){
	var xf_winwidth = $(window).width();
	var xf_winheight = $(window).height();
	$("html").css("fontSize",xf_winwidth/160*7+"px");

	var zhifuHeight=parseInt($(".zhifuPage").css("height"))-xf_winwidth/160*7*3;
	if(zhifuHeight<xf_winheight){
		$(".tc_zhifuuser").addClass("cur");
	}else{
		$(".tc_zhifuuser").removeClass("cur");
	}
});
window.onload=function(){
    $(".loading").hide();
};;;;;

